package com.lijin.service.impl;

import com.lijin.dao.LotteryDao;
import com.lijin.domain.entity.Lottery;
import com.lijin.service.LotteryService;
import java.util.Date;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;

/**
 * Created by gold-jx on 2017/5/27.
 */
@Service
@Slf4j
public class LotteryServiceImpl implements LotteryService {

  @Autowired
  private LotteryDao lotteryDao;

  @Override
  @Transactional
  public void addLottery(Lottery lottery) {
    try {
      Assert.notNull(lottery, "参数不能为空");
      lottery.setState("NORMAL");
      lottery.setCreateTime(new Date());
      lottery.setModifyTime(new Date());

      lotteryDao.insertLottery(lottery);

    } catch (Exception e) {
      log.error("添加彩种失败", e);
    }

  }

  @Override
  public void deleteLottery(String code) {
    try {
      Assert.notNull(code, "彩种编码不能为空");

      lotteryDao.deleteLottery(code);

    } catch (Exception e) {
      log.error("删除彩种失败", e);
    }
  }

  @Override
/*  @Cacheable(cacheNames = "Lotterys", key = "#code")*/
  public List<Lottery> findByCode(String code) {
    List<Lottery> list;
    if (StringUtils.isEmpty(code)) {
      log.error("彩种编码为空");
      return null;
    } else {
      list = lotteryDao.findByCode(code);
    }
    //log.info("开始查询Lottery表");
    return list;
  }
}
